//获取cookie,
export default {
    setCookie(name, value, days) {
        var expires = "";
        if (days) {
            var date = new Date();
            date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
            expires = "; expires=" + date.toUTCString();
        }
        document.cookie = name + "=" + (value || "") + expires + "; path=/";
    },
    getCookie(name) {
        var nameEQ = name + "=";
        var ca = document.cookie.split(';');
        for (var i = 0; i < ca.length; i++) {
            var c = ca[i];
            while (c.charAt(0) == ' ') c = c.substring(1, c.length);
            if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
        }
        return null;
    },
    deleteCookie(name) {
        // 设置一个过去的日期
        var date = new Date();
        date.setTime(date.getTime() - (1 * 24 * 60 * 60 * 1000)); // 减去一天的时间
        // 为cookie设置过期时间为过去的时间，这会使浏览器认为它已经过期
        document.cookie = name + "=; expires=" + date.toUTCString() + "; path=/";
    },
    // 存储布尔值到cookie
    storeBooleanInCookie(key, value) {
        // 将布尔值转换为字符串
        var stringValue = value.toString();
        cookieAPI.setCookie(key, stringValue, 1); // 存储1天
    },

// 从cookie中读取布尔值
    retrieveBooleanFromCookie(key) {
        var stringValue = cookieAPI.getCookie(key);
        if (stringValue === 'true') {
            return true;
        } else if (stringValue === 'false') {
            return false;
        } else {
            return null; // 如果cookie中没有相应的键或值不是'true'或'false'
        }
    }

}
